package com.qf.business.system.controller;


import com.qf.business.system.service.AdviseService;
import com.qf.data.base.r.R;
import com.qf.data.base.r.Rs;
import com.qf.data.system.entity.Advise;
import com.qf.data.system.vo.input.AdviseInput;
import com.qf.data.system.vo.output.AdviseOutput;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;


/**
 * (Advise)表控制层
 *
 * @author 啊炜
 * @since 2022-06-29 17:10:29
 */
@RestController
@RequestMapping("/advise")
public class AdviseController {

    @Autowired
    private AdviseService adviseService;

    @RequestMapping("/list")
    public R list(){
        List<Advise> advises = adviseService.list();

        List<AdviseOutput> outputs = advises.stream()
                .map(advise ->{
                    AdviseOutput adviseOutput =new AdviseOutput();
                    BeanUtils.copyProperties(advise,adviseOutput);
                    return adviseOutput;
                }).collect(Collectors.toList());
        return Rs.create(outputs);
    }

    @RequestMapping("/insert")
    public R insert(AdviseInput adviseInput){
        Advise advise = new Advise();
        BeanUtils.copyProperties(adviseInput,advise);
        //保存
        adviseService.save(advise);
        return Rs.create("succ");
    }

    @RequestMapping("/")
    public R UpAndDown(){

        return Rs.create("succ");
    }



}

